package cn.oms.oms.controller;


import cn.oms.oms.entity.Bill;
import cn.oms.oms.entity.Department;
import cn.oms.oms.service.IBillService;
import cn.oms.oms.service.IDepartmentService;
import cn.oms.oms.vo.BillVo;
import cn.oms.oms.vo.DepartmentVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/department")
@Slf4j
public class DepartmentController {

    @Autowired
    public IDepartmentService departmentService;

    /**
     * 根据查询条件查询科室列表
     * @param departmentVo
     * @return
     */
    @PostMapping("/selectDepartmentList")
    public PageInfo<Department> selectDepartmentList(DepartmentVo departmentVo){
        if(departmentVo.getPageNum()==null||departmentVo.getPageNum()==0){
            departmentVo.setPageNum(1);
        }
        if(departmentVo.getPageSize()==null||departmentVo.getPageSize()==0){
            departmentVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",departmentVo);
        PageInfo<Department> pageInfo = departmentService.selectDepartmentList(departmentVo);
        return pageInfo;
    }

    /**
     * 查询科室详情
     * @param departmentVo
     * @return
     */
    @PostMapping("/selectDepartmentDetail")
    public Department selectDepartmentDetail(DepartmentVo departmentVo){
        log.debug("接收到信息:{}",departmentVo);
        Department department = departmentService.selectDepartmentDetail(departmentVo);
        return department;
    }

    /**
     * 新增科室
     * @param departmentVo
     * @return
     */
    @PostMapping("/addDepartment")
    public String addDepartment(DepartmentVo departmentVo){
        log.debug("接收到信息:{}",departmentVo);
        String res = departmentService.addDepartment(departmentVo);
        return res;
    }

    /**
     * 修改科室
     * @param departmentVo
     * @return
     */
    @PostMapping("/updateDepartment")
    public String updateDepartment(DepartmentVo departmentVo){
        log.debug("接收到信息:{}",departmentVo);
        String res = departmentService.updateDepartment(departmentVo);
        return res;
    }

    /**
     * 删除科室
     * @param id
     * @return
     */
    @GetMapping("/deleteDepartment/{id}")
    public String deleteDepartment(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = departmentService.deleteDepartment(id);
        return res;
    }

}
